import React, { useEffect, useState } from 'react'
import AskListItem from "./AskListItem"
import { getMyAsk } from "../../api/ask"
import {Pagination} from "antd"
import './MyAsking.scss'
export default function MyAsking() {
    const [askParams, setAskParams] = useState({
        pageNum: 1,
        pageSize: 10,
        questionTitle: ""
    })
    const [pageTotal,setPageTotal] = useState(0)
    const [list,setList] = useState([])
    const [flag,setFlag] = useState(false)
    const getAskList = async () => {
        let res = await getMyAsk(askParams)
        setList(res.data.rows);
        setPageTotal(res.data.total)
    }
    useEffect(() => {
        getAskList()
    }, [askParams,flag])
    const changeSearchValue = (e) => {
        setAskParams({
            ...askParams,
            questionTitle:e.target.value
        })
    }
    const onChange = (pageNumber) => {
        setAskParams({
            ...askParams,
            pageNum:pageNumber
        })
    }
    const init = () => {
        setFlag(!flag)
    }
    return (
        <div className="ask_left_big">
            <div className="ask_answer-top">
                <input placeholder="搜索" value={askParams.questionTitle} onChange={(e)=>{
                    changeSearchValue(e)
                }}/>
            </div>
            <div className="ask_answer-bottom">
                {
                    list&&list.map(item=>{
                        return <AskListItem init={init} ask={true} key={item.answerId} obj={item}/>
                    })
                }
            </div>
            <div>
                <Pagination defaultCurrent={2} total={pageTotal} onChange={onChange} />
            </div>
        </div>
    )
}
